// pages/demo/index.js
const { chooseImage, checkImageSecurity, navTo } = require('../../common/env');
import { DEFAULT_BG_LIST } from '../../constants/common';
import { PACKAGE_MARKET_PAGE } from '../../constants/route'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        testFunction: [],
        activeNames: [],
        activeCommonNames: [],
        activeFuncNames: [],
        showRemark: false,
        showPopupPicker: false,
        showAreaPicker: false,
        showBankPicker: false,
        showDatetimePicker: false,
        showSelectExpress: false,
        showExpressModal: false,
        activityInfo: {},
        imagePath: '',
        imageSecurity: false,
        pictureList: DEFAULT_BG_LIST,
        productItemInfo: { name: '测试', price: 20, pic: '', count: 0 },
        productList: [{
            name: '商品名称', // 名称
            price: 20, // 价格
            pic: 'https://img14.360buyimg.com/n7/jfs/t1/123836/29/9634/164651/5f37b4fdE6851322f/f221f1f4c4fb03ce.jpg', // 图片
            count: 1, // 已选数量
            selectSku: '黑色/M',
        }, {
            name: '商品名称', // 名称
            price: 20, // 价格
            pic: 'https:////img12.360buyimg.com/n7/jfs/t1/148350/13/5533/153231/5f37b3edE80e6d4fa/232d7a145be1daa9.jpg', // 图片
            count: 1, // 已选数量
            selectSku: '黑色/M',
        }, {
            name: '商品名称', // 名称
            price: 20, // 价格
            pic: 'https:////img14.360buyimg.com/n7/jfs/t1/135264/5/7025/155153/5f37b3edE8b89334d/7c27799ee828156f.jpg', // 图片
            count: 1, // 已选数量
            selectSku: '黑色/M',
        }, {
            name: '商品名称', // 名称
            price: 20, // 价格
            pic: 'https:////img10.360buyimg.com/n7/jfs/t1/127300/37/9858/176736/5f37b918E0d1d6a5c/fc838e65d370272a.jpg', // 图片
            count: 1, // 已选数量
            selectSku: '黑色/M',
        }],
    },

    gotoFlipPage: function () {
        navTo(PACKAGE_MARKET_PAGE.flip);
    },
    gotoFuritPage: function () {
        navTo(PACKAGE_MARKET_PAGE.fruit);
    },
    gotoWheelPage: function () {
        navTo(PACKAGE_MARKET_PAGE.wheel);
    },

    onChangeTestFunction: function (event) {
        this.setData({
            testFunction: event.detail,
        });
    },

    openSelectAddress: function () {
        wx.chooseLocation({
            success(res) {
                console.log('Demo => 获取的地址为：', res);
            }
        });
    },

    onChange: function (event) {
        this.setData({
            activeNames: event.detail,
        });
    },

    onCommonChange: function (event) {
        this.setData({
            activeCommonNames: event.detail,
        });
    },

    onFuncChange: function (event) {
        this.setData({
            activeFuncNames: event.detail,
        });
    },

    rightAction: function() {
        wx.showToast({
          title: '你点击了复制按钮',
        })
    },

    // 打开备注
    openRemark: function () {
        this.setData({
            showRemark: true,
        });
    },
    remarkValue: function(event) {
        console.log('Demo => 返回的备注信息为：', event.detail);
    },

    // 选择器popup
    openPopupPicker() {
        this.setData({
            showPopupPicker: true,
        });
    },
    confirmPopupPicker(e) {
        console.log('Demo => 返回的信息为：', e.detail);
    },

    // 地区选择器popup
    openAreaPicker() {
        this.setData({
            showAreaPicker: true,
        });
    },
    confirmAreaPicker(e) {
        console.log('Demo => 返回的信息为：', e.detail);
    },

    // 银行选择器popup
    openBankPicker() {
        this.setData({
            showBankPicker: true,
        });
    },
    confirmBankPicker(e) {
        console.log('Demo => 返回的信息为：', e.detail);
    },

    // 日期时间选择器popup
    openDatetimePicker() {
        this.setData({
            showDatetimePicker: true,
        });
    },
    confirmDatetimePicker(e) {
        console.log('Demo => 返回的信息为：', e.detail);
    },
    userMoreAction: function (event) {
        wx.showToast({
            title: '点击user-list-item更多 => ' + event.detail,
            icon: 'none',
        })
    },
    userClickAction: function (event) {
        wx.showToast({
            title: '点击user-list-item的click => ' + event.detail,
            icon: 'none',
        })
    },
    // 用户资产
    userAssetBalanceAction: function (event) {
        wx.showToast({
            title: '点击user-asset的balance ',
            icon: 'none',
        })
    },
    userAssetWithdrawAction: function (event) {
        wx.showToast({
            title: '点击user-asset的withdraw ',
            icon: 'none',
        })
    },
    // 用户提现
    userWithdrawApplyAction(e) {
        wx.showToast({
            title: '点击user-asset的apply => ' + e.detail,
            icon: 'none',
        })
    },
    monthChangeAction: function (event) {
        wx.showToast({
            title: '月份修改了 => ' + JSON.stringify(event.detail),
            icon: 'none',
        })
    },
    editAction: function () {
        wx.showToast({
            title: '点击了编辑',
            icon: 'none',
        })
    },
    shareAction: function () {
        wx.showToast({
            title: '点击了分享',
            icon: 'none',
        })
    },
    // 筛选器bar
    filterBarChangeAction(e) {
        wx.showToast({
            title: '当前filter值 => ' + JSON.stringify(e.detail),
            icon: 'none',
        });
    },
    // 步骤bar
    stepsBarClickAction(e) {
        wx.showToast({
            title: '当前点击的step值 => ' + e.detail,
            icon: 'none',
        });
    },
    // 活动项
    clickActivityActin() {
        wx.showToast({
            title: '点击了',
            icon: 'none',
        })
    },
    shareActivityActin() {
        wx.showToast({
            title: '点击了分享',
            icon: 'none',
        })
    },
    moreActivityActin() {
        wx.showToast({
            title: '点击了更多',
            icon: 'none',
        })
    },
    spokesActivityActin() {
        wx.showToast({
            title: '点击了代言',
            icon: 'none',
        })
    },
    async openSelectImage() {
        const filePath = await chooseImage();
        console.log('DEMO => 选择的图片结果为：', filePath);
        console.log('DEMO => 检查是否安全');
        const flag = await checkImageSecurity(filePath[0]);
        console.log('DEMO => 检验结果：', flag);
        this.setData({
            imagePath: filePath,
            imageSecurity: flag,
        });
    },
    selectPictureChange(event) {
        console.log('DEMO => 选择图片修改，', event.detail);
    },
    productItemChangeAction(e) {
        this.setData({
            productItemInfo: e.detail
        });
    },
    productItemMinusAction() {
        wx.showToast({
            title: '点击了减',
            icon: 'none',
        })
    },
    productItemPlusAction() {
        wx.showToast({
            title: '点击了加',
            icon: 'none',
        })
    },
    openShoppingCart() {
        this.setData({
            showShoppingCart: true,
        });
    },
    closeShoppingCart() {
        console.log('DEMO => 关闭购物车');
        this.setData({
            showShoppingCart: false,
        });
    },
    clearShoppingCart() {
        console.log('DEMO => 清空购物车');
    },
    minusShoppingCart() {
        console.log('DEMO => 购物车减少商品');
    },
    addShoppingCart() {
        console.log('DEMO => 购物车添加商品');
    },
    openSelectExpress() {
        this.setData({
            showSelectExpress: true,
        });
    },
    changeExpressResult(event) {
        console.log('Demo => 选择快递的结果：', event.detail);
    },
    getQrcodeFile(event) {
        console.log('Demo => 二维码临时路径：', event.detail);
    },
    openExpressModal() {
        this.setData({
            showExpressModal: true,
        });
    },
    expressModalAction(event) {
        console.log('Demo => 返回的信息为：', event.detail);
    },
})   
